package com.yixun.qfbao.controller;

import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author zilong.liu
 * @date 2020-11-16
 *
 * desc:
 *     版本控制
 *    	 每次发版本之后强行刷新版本号进行控制
 */

import com.yixun.qfbao.constant.RedisKeyConstant;
import com.yixun.qfbao.util.RedisUtil;

@Controller
@ResponseBody
@RequestMapping("/version")
@DependsOn("springContextUtil")
public class VersionController {
	
	@PostMapping("/getVersion")
	public String getVersion() {
		return String.valueOf(RedisUtil.get(RedisKeyConstant.Version.ASSISTANT_CURRENT_VERSION));
	}
	
	@PostMapping("/getAssistantVersion")
	public String getAssistantVersion() {
		return String.valueOf(RedisUtil.get(RedisKeyConstant.Version.ASSISTANT_CURRENT_VERSION));
	}
	
	@PostMapping("/getAgencyVersion")
	public String getAgencyVersion() {
		return String.valueOf(RedisUtil.get(RedisKeyConstant.Version.AGENCY_CURRENT_VERSION));
	}
	
	//每次只保存两个版本
	@GetMapping("/refershAssistantVersion")
	public void refershAssistantVersion(String version) {
		setAssistantVersion(version);
	}
	
	@GetMapping("/refershAgencyVersion")
	public void refershAgencyVersion(String version) {
		setAgencyVersion(version);
	}
	
	private void setAssistantVersion(String version) {
		RedisUtil.set(RedisKeyConstant.Version.ASSISTANT_CURRENT_VERSION, version);
	}
	
	private void setAgencyVersion(String version) {
		RedisUtil.set(RedisKeyConstant.Version.AGENCY_CURRENT_VERSION, version);
	}
}
